package dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import connectUtil.ConnectionUtil;
import entity.Tour;

public class SearchTour {

	private static Connection conn;
    private static CallableStatement callProc;
    private static ResultSet rs;
	public static ArrayList<Tour> searchTour(String tag){
		ArrayList<Tour> list = new ArrayList<Tour>();
		Tour e = null;
		try{
			conn = ConnectionUtil.getConnection();
    		callProc = conn.prepareCall("{call SearchTour(?)}");
    		callProc.setString(1,tag);
    		rs = callProc.executeQuery();
    		while(rs.next()){
    			e = new Tour();
    			e.setId(rs.getInt("id"));
    			e.setTourName(rs.getString("tourName"));
    			e.setPlace(rs.getString("place"));
    			e.setStartDate(rs.getDate("startDate"));
    			e.setEndDate(rs.getDate("endDate"));
    			e.setPrice(rs.getFloat("price"));
    			e.setMaxVisitors(rs.getShort("maxVisitors"));
    			e.setCurrentVisitors(rs.getShort("currentVisitors"));   		
    			list.add(e);
    		}
		}catch(Exception ex){
			System.out.println(" Error : " + ex.getMessage());
		}
		finally{
			try {
				if(conn!=null){
					conn.close();
				}
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		}
		System.out.println(" so luong Tour tim duoc: " + list.size());
		return list;
	}
	
	public static void main(String[] args) {
		ArrayList<Tour> list = searchTour("bn");
		System.out.println(list.size());
	}

}
